import {
    addActivityCategoryService,
    addInfoCategoryService,
    updateActivityCategoryService,
    updateInfoCategoryService,
    delActivityCategoryService,
    delInfoCategoryService,
} from "@/api/admin/common";
import { message, messageType } from '@/utils/message'

const state = {
};
const mutations = {
};
const actions = {
    // 添加活动类别
    async addActivityCategoryActions(context, from) {
        console.log('from-->',from);
        await addActivityCategoryService(from).then(resp => {
            if (!resp) return;
            message(messageType().success, '添加成功')
            console.log('addActivityCategoryActions-->', resp.data);
        }, error => {
            console.log(error);
        })
    },

    // 修改活动类别
    async updateActivityCategoryActions(context, from) {
        await updateActivityCategoryService(from).then(resp => {
            if (!resp) return;
            message(messageType().success, '修改成功')
            console.log('updateActivityCategoryActions-->', resp.data);
        }, error => {
            console.log(error);
        })
    },

    // 删除活动类别
    async delActivityCategoryActions(context, id) {
        await delActivityCategoryService(id).then(resp => {
            if (!resp) return;
            message(messageType().success, '操作成功')
            console.log('delActivityCategoryActions-->', resp.data);
        }, error => {
            console.log(error);
        })
    },

    // 添加资讯类别
    async addInfoCategoryActions(context, from) {
        await addInfoCategoryService(from).then(resp => {
            if (!resp) return;
            message(messageType().success, '添加成功')
            console.log('addInfoCategoryActions-->', resp.data);
        }, error => {
            console.log(error);
        })
    },

    // 修改资讯类别
    async updateInfoCategoryActions(context, from) {
        await updateInfoCategoryService(from).then(resp => {
            if (!resp) return;
            message(messageType().success, '修改成功')
            console.log('updateInfoCategoryActions-->', resp.data);
        }, error => {
            console.log(error);
        })
    },

    // 删除资讯类别
    async delInfoCategoryActions(context, id) {
        await delInfoCategoryService(id).then(resp => {
            if (!resp) return;
            message(messageType().success, '操作成功')
            console.log('delInfoCategoryActions-->', resp.data);
        }, error => {
            console.log(error);
        })
    },

};

export default {
    namespaced: true,
    state,
    mutations,
    actions,
}